package ar.edu.itba.jMEBowling.scoring;

import ar.edu.itba.jMEBowling.Runner;

import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.Text;

public class ScoreDisplay {

	private int screenWidth;
	private int screenHeight;
	private Node statNode;
	private Runner game;
	private Text[] points = new Text[11];

	public ScoreDisplay(Node statNode, int screenWidth, int screenHeight,
			Runner game) {
		this.screenHeight = screenHeight;
		this.screenWidth = screenWidth;
		this.statNode = statNode;
		this.game = game;
		int i = 0;
		while (i < 11) {
			Text point = Text.createDefaultTextLabel("P" + i);
			point.setLocalTranslation(i * 50, screenHeight - 30, 0);
			point.setLocalScale(2f);
			point.print("-");
			point.setTextColor(ColorRGBA.white);
			points[i] = point;
			i++;
		}
		showPoints();
	}

	public void showPoints() {
		int i = 0;
		while (i < 11) {
			statNode.attachChild(points[i]);
			i++;
		}
	}

	public void update(Scoring scoring) {
		int i = 0;
		while (i < scoring.getShoot()) {
			Text text = points[i];
			text.print(scoring.getPointsTotal().get(i).toString());
			points[i] = text;
			i++;
		}
		Text full = points[10];
		full.print((new Integer(scoring.getFinalResults()).toString()));

	}

	public int getScreenWidth() {
		return screenWidth;
	}

	public void setScreenWidth(int screenWidth) {
		this.screenWidth = screenWidth;
	}

	public int getScreenHeight() {
		return screenHeight;
	}

	public void setScreenHeight(int screenHeight) {
		this.screenHeight = screenHeight;
	}

	public Node getStatNode() {
		return statNode;
	}

	public void setStatNode(Node statNode) {
		this.statNode = statNode;
	}

	public Runner getGame() {
		return game;
	}

	public void setGame(Runner game) {
		this.game = game;
	}

	public void reset() {
		int i = 0;
		while (i < 11) {
			points[i++].print("-");
		}

	}

}
